Skip to content

feat: handle right clicks properly#2885

Merged
Saadnajmi merged 6 commits intomicrosoft:mainfrom
Saadnajmi:saadnajmi/onAuxClick
Apr 9, 2026
Merged

feat: handle right clicks properly#2885
Saadnajmi merged 6 commits intomicrosoft:mainfrom
Saadnajmi:saadnajmi/onAuxClick

Conversation

@Saadnajmi
Copy link
Copy Markdown
Collaborator

@Saadnajmi Saadnajmi commented Apr 2, 2026

Summary

  • Implements onAuxClick event, matching the upstream implementation in facebook/react-native#56298
  • Shared changes (from upstream): Adds onAuxClick/onAuxClickCapture to TouchEventEmitter, ViewEvents (primitives.h), propsConversions.h, BaseViewConfig.ios.js (bubbling event), RCTSurfacePointerHandler.mm (iOS dispatch), and PointerEventProps types
  • macOS-specific changes: Since macOS doesn't use RCTSurfacePointerHandler.mm (guarded with #if !TARGET_OS_OSX), adds native wiring through RCTViewComponentView.mm (rightMouseUp:HostPlatformViewEventEmitter::onAuxClick)
  • Adds a button field to the macOS MouseEvent struct (W3C spec: 0=left, 1=middle, 2=right)
  • Filters non-primary button clicks from triggering onPress in Pressability, so right-clicking a Pressable no longer fires its press handler

Test plan

Event log matches my button presses

Screenshot 2026-04-08 at 3 38 45 PM

🤖 Generated with Claude Code

Implements onAuxClick following the same pattern as onDoubleClick, wired
end-to-end from native rightMouseUp: through C++ event emitters to JS.
Also adds a `button` field to MouseEvent and filters non-primary button
clicks from triggering onPress in Pressability.

Inspired by microsoft/react-native-windows#15920.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 2, 2026

⚠️ No Changeset found

Latest commit: 3419ec0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Port the shared changes from facebook#56298:
- Add onAuxClick/onAuxClickCapture to TouchEventEmitter (shared C++)
- Add AuxClick/AuxClickCapture to ViewEvents in primitives.h
- Add prop conversions in propsConversions.h
- Register topAuxClick as a bubbling event in BaseViewConfig.ios.js
- Add dispatch logic in RCTSurfacePointerHandler.mm (iOS path)
- Type onAuxClick as PointerEvent in PointerEventProps (Flow + TS)

Remove redundant macOS-specific JS registrations since macOS now
inherits the bubbling event from the iOS base config.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ArshVermaGit

This comment was marked as low quality.

Saadnajmi and others added 2 commits April 8, 2026 11:58
Match react-native-windows approach: add _isDefaultPressButton() helper
and use it in all three press paths (onClick, LONG_PRESS_DETECTED, and
RESPONDER_RELEASE). The button property is already forwarded from native
macOS touch events via BaseTouch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add MouseClickEventsExample to ViewExample.js with both a plain View
  and a Pressable target to verify onAuxClick fires and onPress does not
  on right-click
- Document onAuxClick in docsite view-events.md with event data spec
  and usage example
- Add button property to onDoubleClick event data docs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Saadnajmi Saadnajmi marked this pull request as ready for review April 8, 2026 23:00
@Saadnajmi Saadnajmi requested a review from a team as a code owner April 8, 2026 23:00
@Saadnajmi Saadnajmi changed the title Add onAuxClick event for right-click handling feat: handle right clicks properly Apr 8, 2026
…ght-click

- Add onClick event for left single-click on plain Views (macOS)
- Fix onAuxClick by adding missing VIEW_EVENT_CASE_MACOS entries in setProp
- Override rightMouseDown: to prevent context menu modal from consuming rightMouseUp:
- Add otherMouseDown:/otherMouseUp: for middle-click (button=1) via onAuxClick
- Add pointerType:"mouse" to mouse event payload for Pressability guard
- Add onAuxClick to Paper architecture (RCTView.h, RCTViewManager.m)
- Guard Pressability _activate against non-primary buttons to prevent
  visual pressed state on right-click/middle-click

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Saadnajmi Saadnajmi force-pushed the saadnajmi/onAuxClick branch from d868993 to 4b76671 Compare April 8, 2026 23:02
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Saadnajmi Saadnajmi enabled auto-merge (squash) April 9, 2026 20:34
Saadnajmi added a commit that referenced this pull request Apr 9, 2026
## Summary
Backport of #2885 to 0.81-stable.

- Add `onAuxClick` event for right-click and middle-click handling on
macOS
- Add `onClick` event for left single-click on plain Views
- Fix `onAuxClick` prop registration in iterator-based setProp path
- Override `rightMouseDown:` to prevent context menu modal from stealing
`rightMouseUp:`
- Add `otherMouseDown:`/`otherMouseUp:` for middle-click support
- Prevent Pressable visual press feedback on non-primary mouse buttons
- Align with upstream facebook#56298 (shared cross-platform
changes)

## Test plan
- Left-click on View → fires `onClick` with `button=0`
- Double-click on View → fires `onDoubleClick` with `button=0`
- Right-click on View → fires `onAuxClick` with `button=2`
- Middle-click on View → fires `onAuxClick` with `button=1`
- Right-click on Pressable → fires `onAuxClick`, does NOT trigger
`onPress` or visual press state

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@Saadnajmi Saadnajmi merged commit 429f532 into microsoft:main Apr 9, 2026
17 checks passed
@Saadnajmi Saadnajmi deleted the saadnajmi/onAuxClick branch April 9, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider using caret range for react-native peer dependency @react-native-community/cli shows outdated macOS setup link for React Native macOS

3 participants